﻿using FreeSql;
using IMES.Common.Domain.DurianModel;
using IMES.Common.Domain.GoldIngotModel;
using IMES.Common.Dtos;
using IMES.Common.Infrastructure;
using MediatR;

namespace GoldIngot.API.Application.Commands.SigningWorkCommand
{
    public class SigningWorkSelectHandler : IRequestHandler<SigningWorkSelectCommand, Result>
    {
        private readonly IBaseRepositorys<SigningWork> signingRep;
        private readonly ILogger<SigningWorkSelectHandler> logger;
        private readonly IBaseRepositorys<SystemLogs> systemRep;

        public SigningWorkSelectHandler(IBaseRepositorys<SigningWork> signingRep, ILogger<SigningWorkSelectHandler> logger, IBaseRepositorys<SystemLogs> systemRep)
        {
            this.signingRep = signingRep;
            this.logger = logger;
            this.systemRep = systemRep;
        }

        /// <summary>
        /// 报工显示
        /// </summary>
        /// <param name="request"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        public async Task<Result> Handle(SigningWorkSelectCommand request, CancellationToken cancellationToken)
        {
            var quest = new Result() { Code = (int)CodeEnum.success };
            var list = signingRep.GetAll().Where(x => x.SigningWorkDeleted == false);
            quest.Data = list;
            logger.LogInformation("报工显示成功");
            SystemLogs system = new SystemLogs { SystemLogsId = request.SystemLogsId, LogeName = "报工显示", LogeTime = DateTime.Now };
            systemRep.AddAsync(system);
            return quest;
        }
    }
}
